package com.emns.service.yuedu;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emns.dao.YueduCommentMapper;
import com.emns.pojo.YueduComment;
import common.DateUtils;
import common.PageInfo;

@Service
public class YueduCommentService {

	@Autowired
	YueduCommentMapper ydcm;

	public void queryPageAll(int yueduId, String cContent, String startDate,
			String endDate, PageInfo<YueduComment> pageInfo) {
		Date sDate = null;
		Date eDate = null;
		if (cContent != null && !"".equals(cContent))
			cContent = "%" + cContent + "%";
		else
			cContent = null;
		if ((startDate != null && !"".equals(startDate))
				&& (endDate != null && !"".equals(endDate))) {
			startDate = startDate + " 00:00:00";
			sDate = DateUtils.parseDate(startDate, "yyyy-MM-dd HH:mm:ss");
			endDate = endDate + " 23:59:59";
			eDate = DateUtils.parseDate(endDate, "yyyy-MM-dd HH:mm:ss");
		} else {
			startDate = null;
			endDate = null;
		}
		List<YueduComment> yuduCommentList = ydcm.getCommentRecordPage(yueduId,
				cContent, sDate, eDate, pageInfo);
		int count = ydcm.getCommentRecordCount(yueduId, cContent, sDate, eDate);
		pageInfo.setDataArray(yuduCommentList);
		pageInfo.setPageCount(count);
	}

	public void delete(Integer[] ids) {
		for (Integer id : ids) {
			if (id != null) {
				YueduComment comment = new YueduComment();
				comment.setCommentId(id);
				comment.setState(2);
				ydcm.updateByPrimaryKeySelective(comment);
			}
		}
	}

	public void audit(Integer[] ids, boolean pass) {
		for (Integer id : ids) {
			if (id != null) {
				YueduComment comment = new YueduComment();
				comment.setCommentId(id);
				if (pass)
					comment.setState(1);
				else
					comment.setState(0);
				ydcm.updateByPrimaryKeySelective(comment);
			}
		}
	}

}
